<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    body {
      background: rgb(110, 110, 110);
      text-align: center;
    }

    #c1 {
      background: white;
    }

    h1 {
      color: orange;
    }
  </style>
  <script>
    window.onload = function() {
      let oC = document.getElementById('c1');
      let gd = oC.getContext('2d');

      let i = 0,
        j = 0;
      let FrameCount = 0;
      let pause = false;

      let oImg = new Image();
      oImg.src = 'fish1.png';

      oImg.onload = function() {
        requestAnimationFrame(next);


        function next() {

          if (!pause) {
            if (FrameCount % 5 == 0) {

              if (i == 4) {
                i = 0;
              }

              gd.clearRect(0, 0, oC.width, oC.height);
              gd.drawImage(
                oImg,
                0, 37 * i++, 55, 37,
                150 + j, 150, 55, 37
              )
              j += 5;
            }

          }

          FrameCount++;
          requestAnimationFrame(next);
        }
      };

      document.onclick = function() {
        pause = !pause;
      };
    };
  </script>
</head>

<body>
  <h1>canvas-fish</h1>
  <canvas id="c1" width="800" height="450"></canvas>
</body>

</html>
